/* 
 * File:   Xpack.h
 * Author: minaev
 *
 * Created on 30 Октябрь 2013 г., 10:07
 */

#ifndef XPACK_H
#define	XPACK_H
#include <stdint.h>
#include <unistd.h>

#define XAPI_AT_IM      0x08
#define XAPI_AT_QU      0x09
#define XAPI_RC_REQ     0x17
#define XAPI_AT_RESP    0x88
#define XAPI_MOD_STAT   0x8A
#define XAPI_TX_REQ     0x10
#define XAPI_TX_RESP    0x8B
#define XAPI_RX_RECV    0x90
#define XAPI_RX_IO_RECV 0x92
#define XAPI_NODE_IND   0x95
#define XAPI_RC_RESP    0x97

class Xpack {
public:
    Xpack();
    Xpack(char* frm);
    virtual ~Xpack();
    int pack(char* frm);
    char* toBytes();
    uint8_t getByte(uint16_t indx);
    uint16_t getLength();
    uint8_t getType();
    char* getData();
    uint8_t getCRC();
    bool checkCRC();
    uint8_t calcCRC();
    void setCRC();
    void setType();
    void setInPack(const char* buf,int len,int offset);
    void setInPack(const char ch, int offset);
    void setInPack(const uint8_t num, int offset);
    void setInPack(const uint16_t num, int offset);
    void setInPack(const uint32_t num, int offset);
    void setInPack(const uint64_t num, int offset);
    void addToPack(const char* buf,int len);
    void addToPack(const char ch);
    void addToPack(const uint8_t num);
    void addToPack(const uint16_t num);
    void addToPack(const uint32_t num);
    void addToPack(const uint64_t num);
    void packAsATcmd(const char* atcmd,void* param,uint16_t len);
    void packAsRemoteATcmd(const uint32_t destAddr, const char* atcmd,void* param,uint16_t len);
    void setAddrRemoteATcmd(const uint32_t destAddr);
    void printPack();
private:
    uint16_t length; //length of frame data
    uint8_t type;  // type of frame
    char* data; // data of frame
    uint8_t crc; //crc of frame
};

typedef Xpack* pXpack;

#endif	/* XPACK_H */

